<template>
    <div class="read">
        <!-- <p class="readP">车厂已读列表</p>
        <FilterTable
        ref="table"
        :columns="columns"
        :dataSource="dataSource"
        :datakey="'records'"
        :isSelectColumn='false'
        :isPagination="false"
        :onColumnsChange="columns => this.columns = columns"
        >
        <template slot="controls" slot-scope="props">
            <el-button size="small" type="primary" icon="el-icon-plus" @click="exportHandle">导出</el-button>
        </template>
        </FilterTable> -->
        <p class="readP">经销商已读列表</p>
        <!-- <FilterTable
        ref="table2"
        :columns="columns2"
        :dataSource="dataSource2"
        :datakey="'records'"
        :isSelectColumn='false'
        :isPagination="false"
        :onColumnsChange="columns2 => this.columns2 = columns2"
        > -->
        <FilterTable
        ref="table2"
        :columns="columns2"
        :fetchapi="fetchApi"
        :params="fetchParams"
        :datakey="'records'"
        :isSelectColumn='false'
        :isPagination="false"
        :onColumnsChange="columns => this.columns = columns"
        >
        
        <template slot="controls" slot-scope="props">
            <el-button size="small" type="primary" icon="el-icon-plus" @click="exportHandle">导出</el-button>
        </template>
        </FilterTable>
    </div>
</template>

<script>
import { dictionary } from '@/utils/dictMixin';
import { getIsReadList,getJxsIsReadList,exportOrders} from '@/api/admin/notice/dcsNoticeMaintain/index';
import {formatDates} from '@/utils/validate'
export default {
    name: 'read',
    mixins: [dictionary],
    props:['readData'],
    data() {
        return {
            dataSource:[],
            dataSource2:[],
            fetchApi:getJxsIsReadList,
            fetchParams: {id:''},
            columns: this.createTableColumns(),
            columns2: this.createTableColumns2(),
        }
    },
    created () {
        console.log(this.readData,"this.readData")
      this.fetchParams.id=this.readData.notificationId 
    },
    methods: {
        createTableColumns() {
        return [
                {
                title: '序号',
                dataIndex: 'index',
                width: 80,
                sorter: true,
                render: props => {
                    return <span>{props.row.index + 1}</span>;
                }
                },
                { title: '部门', dataIndex: 'ORG_NAME', sorter: true },
                { title: '用户名', dataIndex: 'ROLE_NAME', sorter: true },
                { title: '角色名称', dataIndex: 'employee_name', sorter: true },
                { title: '首次阅读时间', dataIndex: 'FEEDBACK_TIME', sorter: true,
                render: props => {
                    return <span>{formatDates(props.row.FEEDBACK_TIME)}</span>;
                } },
                
            ];
        },
        createTableColumns2() {
        return [
                {
                title: '序号',
                dataIndex: 'index',
                width: 80,
                sorter: true,
                render: props => {
                    return <span>{props.row.index + 1}</span>;
                }
                },
               /*  { title: '所属区域', dataIndex: 'ORG_NAME', sorter: true },
                { title: '经销商名称', dataIndex: 'DEALER_NAME', sorter: true },
                { title: '员工名称', dataIndex: 'employee_name', sorter: true }, */
                { title: '用户名', dataIndex: 'USER_CODE', sorter: true },
                { title: '员工名称', dataIndex: 'EMPLOYEE_NAME', sorter: true },
                { title: '首次阅读时间', dataIndex: 'CREATED_AT', sorter: true ,
                render: props => {
                    return <span>{formatDates(props.row.FEEDBACK_TIME)}</span>;
                }},
                
            ];
        },
        //导出
        exportHandle() {
            this.$confirm('是否将Excel表格保存至本地文件夹?', '提示', {
            confirmButtonText: '下载',
            cancelButtonText: '取消',
            type: 'warning'
            }).then(() => {
            exportOrders(this.querInfo).then( response => {
            let blob = new Blob([response.data],{type: 'application/vnd.ms-excel'});
            if (window.navigator.msSaveOrOpenBlob) {
                // 如果需要改名字，前台可以自动生成
                navigator.msSaveBlob(blob,"下载的文件");
            } else {
                let link = document.createElement("a");
                let evt = document.createEvent("HTMLEvents");
                evt.initEvent("click", false, false);
                link.href = URL.createObjectURL(blob);
                link.download = "下载的文件";
                link.style.display = "none";
                document.body.appendChild(link);
                link.click();
                window.URL.revokeObjectURL(link.href);
            }
            }).catch( err => {
            console.log(err)
            })

            // this.$message({
            //   type: 'success',
            //   message: '正在下载中'
            // });
            }).catch(() => {
            this.$message({
                type: 'info',
                message: '已取消'
            });
            });
        },
    },
    
}
</script>

<style lang="less" scoped>
.readP{
    background: #eee;
    line-height: 30px;
    padding-left: 10px;
    margin: 10px 0;
}
</style>
